package com.yidi.system.repository;

import com.yidi.common.core.Repository.BaseRepository;
import com.yidi.system.domain.SysUserPost;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;

/**
 * @author ：Xn
 * @ClassName: SysUserPostRepository
 * @date ：2021-10-19 14:08
 * @describe ：用户和岗位
 */
@Repository
public interface SysUserPostRepository extends BaseRepository<SysUserPost,Long> {

    /**
     * 通过岗位ID查询岗位使用数量
     *
     * @param postId 岗位ID
     * @return 结果
     */
    @Query(nativeQuery = true, value = "select count(1) from sys_user_post up where up.post_id = ?1")
    Integer countUserPostById(Long postId);

    /**
     * 通过用户ID删除用户和岗位关联
     *
     * @param userId 用户ID
     * @return 结果
     */
    @Modifying
    @Transactional
    @Query(nativeQuery = true, value = "delete from sys_user_post where user_id=?1")
    void deleteUserPostByUserId(Long userId);
}
